//
//  CalendarSignInStore.m
//  NewPro
//
//  Created by RYX on 2019/1/14.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "CalendarSignInStore.h"

@implementation CalendarSignInStore

#pragma mark - 获取已签到数据
- (void)getSignInListWithCustomId:(NSString *)customId andYear:(NSString *)year andMonth:(NSString *)month Success:(void(^)(NSString *continued,NSArray *listArr))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/v1/sign",IP];
    
    NSDictionary *dic = @{
                          @"customId":customId,
                          @"year":year,
                          @"month":month
                          };
    
    [HttpTool getUrlWithString:url parameters:dic success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        
        if (error == nil) {
            
            NSString *continued = responseObject[@"data"][@"continued"];
            NSArray *arr = responseObject[@"data"][@"dateList"];
            success(continued,arr);
            
        }else{
            
            failure(error);
        }
        
    } failure:^(NSError *error) {
        failure(error);
    }];
    
}

#pragma mark - 签到
- (void)signInWithCustomId:(NSString *)customId Success:(void(^)(void))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/v1/sign/%@",IP,customId];
    
    [HttpTool postUrlWithString:url parameters:nil success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        
        if (error == nil) {
            
            success();
        }else{
            
            failure(error);
        }
        
    } failure:^(NSError *error) {
        failure(error);
    }];
    
}

#pragma mark - 查询积分
- (void)searchIntegralWithCustomId:(NSString *)customId Success:(void(^)(NSString *integral))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/v1/integral",IP];
    
    NSDictionary *dic = @{
                          @"customId":customId,
                          };
    
    [HttpTool getUrlWithString:url parameters:dic success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        
        if (error == nil) {
            
            NSString *integral = responseObject[@"data"][@"integral"];
            success(integral);
            
        }else{
            
            failure(error);
        }
        
    } failure:^(NSError *error) {
        failure(error);
    }];
    
}
@end
